import { DataSource, Entity, Repository } from "typeorm";
import { Config } from "../../config/Config";
import { DbConfig } from "../../config/DbConfig";
import { DBSourceManager } from "../utils/DBSourceManager";
import { Logger } from "../utils/Logger";
import { MysqlClient } from "../utils/MySqlClient";
import { MysqlManager } from "../utils/MysqlManager";

export class DaoBase {


    public static async getRepositoryBase(target: any, dbName: string, dbType: number = DbConfig.now_db_type) {
        let dataSource: DataSource = await DBSourceManager.instance.getDb(dbName, dbType);
        let repository: Repository<any> = dataSource.getRepository(target)
        return repository
    }

    public static getAccountDbName() {
        if (Config.environment == Config.EnvironmentType.Test) {
            return DbConfig.Db_Name.db_account
        }
        else {
            return DbConfig.Db_Name.db_account
        }
    }

    public static getAdminDbName() {
        if (Config.environment == Config.EnvironmentType.Test) {
            return DbConfig.Db_Name.db_admin
        }
        else {
            return DbConfig.Db_Name.db_admin
        }
    }

    public static getGameDbName() {
        if (Config.environment == Config.EnvironmentType.Test) {
            return DbConfig.Db_Name.db_game
        }
        else {
            return DbConfig.Db_Name.db_game
        }
    }

    public static getLogDbName() {
        if (Config.environment == Config.EnvironmentType.Test) {
            return DbConfig.Db_Name.db_log
        }
        else {
            return DbConfig.Db_Name.db_log
        }
    }

}